var layer;
layui.use(['element','form','table','layer','laydate'], function() {
    var $ = layui.jquery,
    form = layui.form,
    layer = layui.layer;

    initAkInfo();

    function initAkInfo() {
        $.get('/cdysylives/getAkInfoByUser', {}, function (result) {
            if (result != null) {
                if (result.resultContent != null) {
                    var akInfo = result.resultContent;
                    setAkInfo(akInfo);
                }
            }
        });
    }

    function setAkInfo(akInfo) {
        if (akInfo) {
            $("#appid").val(akInfo.appKey);
            $("#appsecret").val(akInfo.secret);
        }
    }

    // 保存配置信息
    form.on('submit(saveOrUpdate)', function (data) {
        $.post("/cdysylives/saveAkInfo", data.field, function (result) {
            if (result.resultCode === '000') {
                layer.msg('保存成功', {icon: 1});
                setAkInfo(result.resultContent);
            } else {
                layer.msg(result.resultDesc, {icon: 0});
            }
        });
        return false;
    });
});
